/**
 * 登录
 * @author hanson
 */
define(['jquery','layer'],function($, Layer){
	
	"use strict";
	
	var Page = {}, DOM;
	
	function init(){
		DOM = {
				form: $('#form'),
				inpVerifyCode: $('.inpVerifyCode'),
				imgVerifyCode: $('.imgVerifyCode'),
				btnSubmit: $('.btnSubmit')
		}
	}
	
	Page.main = function(){
		init();
		handleEvent();
	}
	
	function handleEvent(){
		DOM.btnSubmit.click(function(){
			if(Mod.needVerifyCode){
				var verifyCode = DOM.inpVerifyCode.val();
				if(verifyCode==''){
					Layer.alert('验证码不能为空');
					return false;
				}else{
					var formData = DOM.form.serialize();
					$.ajax({
						url:_base + '/login/submit',
						type:'post',
						data: formData,
						dataType:'json',
						success:function(message){
							if(message.type == 'success'){
								window.location.href = _base + '/admin/index';
							}else{
								Layer.alert(message.content);
							}
						}
					});
				}
			}
		});
		
		// 点击  更新验证码图片
		DOM.imgVerifyCode.click(function(){
			var seconds = new Date().getTime();
			var src = _base + '/common/getVerifyCode?s='+seconds;console.log(src);
			$(this).attr('src',src);
		});
		
		// 回车触发登录
		$("body").keydown(function(event) {
            if (event.keyCode == "13") {//keyCode=13是回车键
            	DOM.btnSubmit.click();
            }
        });
	}
	
	
	return Page;
});